package com.accesshollywood.indexables;

import java.lang.reflect.Field;

public class User extends Indexed {
	protected String	firstName;
	protected String	lastName;
	protected long	SSO;
	protected String	emailAddress;
	protected boolean	isAdmin		= false;
	protected boolean	isArtist	= false;
	protected boolean	isFootage	= false;
	protected boolean	isLegal		= false;
	protected boolean	isResearch	= false;
	protected boolean	isPhotoEdit	= false;
	protected boolean	isOrderer	= false;
	protected boolean	isProducer	= false;
	protected boolean	isGuest		= false;

	protected String	IP;					// set this when we find a new connection in the database so we can refresh their machine when we do something
	protected String	IP_local;				// this is THIS machine's IP address

	@Override
	public void initSQL() {
		setThat(this);
		tableName = "person";
		idColumnName = "idPerson";
		elementColumnName.put(getField("SSO"), "SSO");
		elementColumnName.put(getField("firstName"), "firstName");
		elementColumnName.put(getField("lastName"), "lastName");
		elementColumnName.put(getField("emailAddress"), "emailAddress");
		elementColumnName.put(getField("isAdmin"), "isAdmin");
		elementColumnName.put(getField("isArtist"), "isArtist");
		elementColumnName.put(getField("isFootage"), "isFootage");
		elementColumnName.put(getField("isLegal"), "isLegal");
		elementColumnName.put(getField("isResearch"), "isResearch");
		elementColumnName.put(getField("isPhotoEdit"), "isPhotoEdit");
		elementColumnName.put(getField("isOrderer"), "isOrderer");
		elementColumnName.put(getField("isProducer"), "isProducer");
		elementColumnName.put(getField("isGuest"), "isGuest");
//		elementColumnName.put(getField("IP"), "IP");
//		elementColumnName.put(getField("IP_local"), "IP_local");
	}

	public String getFullName() {
		return firstName + " " + lastName;
	}

	public boolean canEditText(GrfxOrder currOrder) {
		if (isAdmin || (isOrderer && !isPhotoEdit) || (isPhotoEdit && this == currOrder.getOrderedBy()) || (isResearch) || (isLegal)) {
			return true;
		} else {
			return false;
		}
	}

	public boolean canEditStills(GrfxOrder currOrder) {
		if (isAdmin || (isOrderer) || (isPhotoEdit) || (isLegal)) {
			return true;
		} else {
			return false;
		}
	}

	public boolean canEditFootage(GrfxOrder currOrder) {
		if (isAdmin || (isOrderer && !isPhotoEdit) || (isFootage) || (isLegal)) {
			return true;
		} else {
			return false;
		}
	}

	public boolean canEditOrder(GrfxOrder currOrder) {
		if (isAdmin || (isOrderer && !isPhotoEdit) || (isPhotoEdit && this == currOrder.getOrderedBy())) {
			return true;
		} else {
			return false;
		}
	}

	public boolean canEditOrderByDepartment(GrfxOrder currOrder, Field field) {
		try {
			if (isAdmin || (isOrderer && !isPhotoEdit) || (isPhotoEdit && this == currOrder.getOrderedBy()) || (boolean) field.getBoolean(this)) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public synchronized String getFirstName() {
		return firstName;
	}

	public synchronized void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public synchronized String getLastName() {
		return lastName;
	}

	public synchronized void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public synchronized long getSSO() {
		return SSO;
	}

	public synchronized void setSSO(long sSO) {
		SSO = sSO;
	}

	public synchronized String getEmailAddress() {
		return emailAddress;
	}

	public synchronized void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public synchronized boolean isAdmin() {
		return isAdmin;
	}

	public synchronized void setAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}

	public synchronized boolean isArtist() {
		return isArtist;
	}

	public synchronized void setArtist(boolean isArtist) {
		this.isArtist = isArtist;
	}

	public synchronized boolean isFootage() {
		return isFootage;
	}

	public synchronized void setFootage(boolean isFootage) {
		this.isFootage = isFootage;
	}

	public synchronized boolean isLegal() {
		return isLegal;
	}

	public synchronized void setLegal(boolean isLegal) {
		this.isLegal = isLegal;
	}

	public synchronized boolean isResearch() {
		return isResearch;
	}

	public synchronized void setResearch(boolean isResearch) {
		this.isResearch = isResearch;
	}

	public synchronized boolean isPhotoEdit() {
		return isPhotoEdit;
	}

	public synchronized void setPhotoEdit(boolean isPhotoEdit) {
		this.isPhotoEdit = isPhotoEdit;
	}

	public synchronized boolean isOrderer() {
		return isOrderer;
	}

	public synchronized void setOrderer(boolean isOrderer) {
		this.isOrderer = isOrderer;
	}

	public synchronized boolean isProducer() {
		return isProducer;
	}

	public synchronized void setProducer(boolean isProducer) {
		this.isProducer = isProducer;
	}

	public synchronized boolean isGuest() {
		return isGuest;
	}

	public synchronized void setGuest(boolean isGuest) {
		this.isGuest = isGuest;
	}

	public synchronized String getIP() {
		return IP;
	}

	public synchronized void setIP(String iP) {
		IP = iP;
	}

	public synchronized String getIP_local() {
		return IP_local;
	}

	public synchronized void setIP_local(String iP_local) {
		IP_local = iP_local;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((IP == null) ? 0 : IP.hashCode());
		result = prime * result + ((IP_local == null) ? 0 : IP_local.hashCode());
		result = prime * result + (int) (SSO ^ (SSO >>> 32));
		result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode());
		result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
		result = prime * result + (isAdmin ? 1231 : 1237);
		result = prime * result + (isArtist ? 1231 : 1237);
		result = prime * result + (isFootage ? 1231 : 1237);
		result = prime * result + (isGuest ? 1231 : 1237);
		result = prime * result + (isLegal ? 1231 : 1237);
		result = prime * result + (isOrderer ? 1231 : 1237);
		result = prime * result + (isPhotoEdit ? 1231 : 1237);
		result = prime * result + (isProducer ? 1231 : 1237);
		result = prime * result + (isResearch ? 1231 : 1237);
		result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (IP == null) {
			if (other.IP != null)
				return false;
		} else if (!IP.equals(other.IP))
			return false;
		if (IP_local == null) {
			if (other.IP_local != null)
				return false;
		} else if (!IP_local.equals(other.IP_local))
			return false;
		if (SSO != other.SSO)
			return false;
		if (emailAddress == null) {
			if (other.emailAddress != null)
				return false;
		} else if (!emailAddress.equals(other.emailAddress))
			return false;
		if (firstName == null) {
			if (other.firstName != null)
				return false;
		} else if (!firstName.equals(other.firstName))
			return false;
		if (isAdmin != other.isAdmin)
			return false;
		if (isArtist != other.isArtist)
			return false;
		if (isFootage != other.isFootage)
			return false;
		if (isGuest != other.isGuest)
			return false;
		if (isLegal != other.isLegal)
			return false;
		if (isOrderer != other.isOrderer)
			return false;
		if (isPhotoEdit != other.isPhotoEdit)
			return false;
		if (isProducer != other.isProducer)
			return false;
		if (isResearch != other.isResearch)
			return false;
		if (lastName == null) {
			if (other.lastName != null)
				return false;
		} else if (!lastName.equals(other.lastName))
			return false;
		return true;
	}

	/*
	 * public int idPerson = 0;
	 * public String firstName;
	 * public String lastName;
	 * public long SSO;
	 * public String emailAddress;
	 * public boolean isAdmin = false;
	 * public boolean isArtist = false;
	 * public boolean isFootage = false;
	 * public boolean isLegal = false;
	 * public boolean isResearch = false;
	 * public boolean isPhotoEdit = false;
	 * public boolean isOrderedBy = false;
	 * public boolean isProducer = false;
	 * public boolean isGuest = false;
	 * public String IP; // set this when we find a new connection in the database so we can refresh their machine when we do something
	 * public String IP_local; // this is THIS machine's IP address
	 * public User() {
	 * }
	 * public String toString() {
	 * return firstName;
	 * }
	 * public String fullName() {
	 * return firstName + " " + lastName;
	 * }
	 * public boolean canEditText(GrfxOrder currOrder) {
	 * if (isAdmin || (isOrderedBy && !isPhotoEdit) || (isPhotoEdit && this == currOrder.getOrderedBy()) || (isResearch) || (isLegal)) {
	 * return true;
	 * } else {
	 * return false;
	 * }
	 * }
	 * public boolean canEditStills(GrfxOrder currOrder) {
	 * if (isAdmin || (isOrderedBy) || (isPhotoEdit) || (isLegal)) {
	 * return true;
	 * } else {
	 * return false;
	 * }
	 * }
	 * public boolean canEditFootage(GrfxOrder currOrder) {
	 * if (isAdmin || (isOrderedBy && !isPhotoEdit) || (isFootage) || (isLegal)) {
	 * return true;
	 * } else {
	 * return false;
	 * }
	 * }
	 * public boolean canEditOrder(GrfxOrder currOrder) {
	 * if (isAdmin || (isOrderedBy && !isPhotoEdit) || (isPhotoEdit && this == currOrder.getOrderedBy())) {
	 * return true;
	 * } else {
	 * return false;
	 * }
	 * }
	 * public boolean canEditOrderByDepartment(GrfxOrder currOrder, Field field) {
	 * try {
	 * if (isAdmin || (isOrderedBy && !isPhotoEdit) || (isPhotoEdit && this == currOrder.getOrderedBy()) || (boolean)field.getBoolean(this)) {
	 * return true;
	 * } else {
	 * return false;
	 * }
	 * } catch (Exception e) {
	 * e.printStackTrace();
	 * }
	 * return false;
	 * }
	 * @Override
	 * public int hashCode() {
	 * final int prime = 31;
	 * int result = 1;
	 * result = prime * result + (int) (SSO ^ (SSO >>> 32));
	 * result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode());
	 * result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
	 * result = prime * result + idPerson;
	 * result = prime * result + (isAdmin ? 1231 : 1237);
	 * result = prime * result + (isArtist ? 1231 : 1237);
	 * result = prime * result + (isFootage ? 1231 : 1237);
	 * result = prime * result + (isGuest ? 1231 : 1237);
	 * result = prime * result + (isLegal ? 1231 : 1237);
	 * result = prime * result + (isOrderedBy ? 1231 : 1237);
	 * result = prime * result + (isPhotoEdit ? 1231 : 1237);
	 * result = prime * result + (isProducer ? 1231 : 1237);
	 * result = prime * result + (isResearch ? 1231 : 1237);
	 * result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
	 * return result;
	 * }
	 * @Override
	 * public boolean equals(Object obj) {
	 * if (this == obj)
	 * return true;
	 * if (obj == null)
	 * return false;
	 * if (getClass() != obj.getClass())
	 * return false;
	 * User other = (User) obj;
	 * if (SSO != other.SSO)
	 * return false;
	 * if (emailAddress == null) {
	 * if (other.emailAddress != null)
	 * return false;
	 * } else if (!emailAddress.equals(other.emailAddress))
	 * return false;
	 * if (firstName == null) {
	 * if (other.firstName != null)
	 * return false;
	 * } else if (!firstName.equals(other.firstName))
	 * return false;
	 * if (idPerson != other.idPerson)
	 * return false;
	 * if (isAdmin != other.isAdmin)
	 * return false;
	 * if (isArtist != other.isArtist)
	 * return false;
	 * if (isFootage != other.isFootage)
	 * return false;
	 * if (isGuest != other.isGuest)
	 * return false;
	 * if (isLegal != other.isLegal)
	 * return false;
	 * if (isOrderedBy != other.isOrderedBy)
	 * return false;
	 * if (isPhotoEdit != other.isPhotoEdit)
	 * return false;
	 * if (isProducer != other.isProducer)
	 * return false;
	 * if (isResearch != other.isResearch)
	 * return false;
	 * if (lastName == null) {
	 * if (other.lastName != null)
	 * return false;
	 * } else if (!lastName.equals(other.lastName))
	 * return false;
	 * return true;
	 * }
	 */
}
